package rothag.views.gamestep.develop;

import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Insets;
import java.awt.RenderingHints;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JToggleButton;
import rothag.graphics.GraphicsHelper;
import rothag.graphics.GraphicsParameters;

/**
 *
 * @author gaetan.revol
 */
public class VendreJToggleButton extends JToggleButton implements MouseListener {

    private boolean isOver;

    public VendreJToggleButton(String text) {
        super(text);

        addMouseListener(this);

        Font font = GraphicsHelper.getFont(13, null);
        setFont(font);
        setMargin(new Insets(0, 0, 0, 0));
        GraphicsHelper.setCursorHand(this);
    }

    @Override
    public void paint(Graphics g) {
        int x = 0;
        int y = 0;

        Graphics2D g2 = (Graphics2D) g;

        if (isOver) {
            g2.setFont(GraphicsHelper.getFont(getFont().getSize(), "bold"));
        } else {
            g2.setFont(GraphicsHelper.getFont(getFont().getSize(), null));
        }

        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g2.setColor(Color.black);
        g2.fillRect(x, y, getWidth(), getHeight());

        g2.drawImage(GraphicsHelper.getImage(GraphicsParameters.pathCadreScore, this), x, y, getWidth(), getHeight(), this);

        FontMetrics fm = getFontMetrics(g2.getFont());
        int stringWidth = fm.stringWidth(getText());
        int stringHeight = (-1) * (g2.getFont().getSize() - 5);
        if (this.isSelected()) {
            g2.setColor(Color.gray);
        } else {
            g2.setColor(Color.white);
        }
        g2.drawString(this.getText(), (getWidth() - stringWidth) / 2, (getHeight() - stringHeight) / 2);
    }

    public void mouseClicked(MouseEvent e) {
    }

    public void mousePressed(MouseEvent e) {
    }

    public void mouseReleased(MouseEvent e) {
    }

    public void mouseEntered(MouseEvent e) {
        isOver = true;
        repaint();
    }

    public void mouseExited(MouseEvent e) {
        isOver = false;
        repaint();
    }
}
